using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana.Common
{
    public class Singleton<T> where T : class, new()
    {
        private static readonly object _lock = new();
        private static T _instance;
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        _instance ??= new T();
                        (_instance as Singleton<T>).OnInit();
                    }
                }

                return _instance;
            }
        }

        protected virtual void OnInit() { }
    }
}